<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>

        //字面量创建对象
        var obj1 = {
            name: 'andy',
            age: 19,
            sayHi: function () {
                console.log('say hi');
            }
        }

        var obj2 = {
            name: 'jack',
            age: 18,
            sayHi: function () {
                console.log('say hi');
            }
        }


        //可以通过函数 抽取相同的部分代码 封装到函数中
        //工厂方法创建对象
        function creatDemo (name,age) {
            //工厂原料 name,age...
            var obj1 = {};

            //对原料进行加工
            obj.name = name;
            obj.age = age;

            //出厂
            return obj;
        }

        //将创建对象的方式 集中处理
        var obj3 = creatDemo('zs',20);
        var obj4 = creatDemo('ls',28);
        var obj5 = creatDemo('ww',25);

        console.log(obj3,obj4);
        
    </script>
</body>

</html>